package com.ibm.spatiotemp.test.requestServer.redis;

import redis.clients.jedis.Jedis;

/** 
 * @author Yaoliang Chen
 * @version May 28, 2014 
 * Description
 */

public class JedisSubThread implements Runnable {

	private String[] topicName;
	private JedisPubSubHandler handler;
	private Jedis jedisClient;
	private int mode;
	
	/**
	 * Constructor
	 * @param mode 1: subscribe 2: psubscribe
	 * @param topic topic name
	 */
	public JedisSubThread(int mode, Jedis jedisClient, JedisPubSubHandler handler, String... topic){
		this.topicName = topic;
		this.handler = handler;
		this.mode = mode;
		this.jedisClient = jedisClient;
	}

	public void run() {
		  try {
          	if(mode == 1){
          		jedisClient.subscribe(handler, topicName);
          	} else if (mode == 2){
          		jedisClient.psubscribe(handler, topicName);
          	}
          } catch (Exception e) {
             e.printStackTrace();
          }
	}

}
